﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FlashCards.Model;

namespace FlashCards.WebApp.Models
{
    public class AddFriendToGroupModel
    {
        public GroupModel Group { get; set; }
        public List<FriendInGroupModel> Friends { get; set; }

        public AddFriendToGroupModel(Group group, List<User> friends, List<User> groupMembers)
        {
            Group = new GroupModel(group);
            Friends = new List<FriendInGroupModel>();

            foreach (var friend in friends)
            {
                var newFriendInGroupModel = new FriendInGroupModel(friend);
                if (groupMembers.FirstOrDefault(x => x.UserId == friend.UserId) != null)
                    newFriendInGroupModel.IsAlreadyInGroup = true;

                Friends.Add(newFriendInGroupModel);
            }
        }
    }
}